home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / CBPUTR.C < prev    next >
Text File  |  1991-09-23  |  3KB  |  114 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)cbputr.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10.  
  11. /* library headers */
  12. #include <lseq.h>
  13.  
  14. /* local headers */
  15. #include "cbase_.h"
  16.  
  17. /*man---------------------------------------------------------------------------
  18. NAME
  19.      cbputr - put cbase record
  20.  
  21. SYNOPSIS
  22.      #include <cbase.h>
  23.  
  24.      int cbputr(cbp, buf)
  25.      cbase_t *cbp;
  26.      const void *buf;
  27.  
  28. DESCRIPTION
  29.      The cbputr function overwrites the current record of cbase cbp.
  30.      The record cursor and all key cursors are positioned to the
  31.      modified record.
  32.  
  33.      If the new record contents cannot be inserted because of an
  34.      illegal duplicate key, the original record is not restored.
  35.      More complete control of the actions taken to exceptions such as
  36.      this can be gained by overwriting a record using a series of
  37.      function calls to search, delete, and insert, rather than a
  38.      single call to cbputr.
  39.  
  40.      cbputr will fail if one or more of the following is true:
  41.  
  42.      [EINVAL]       cbp is not a valid cbase pointer.
  43.      [EINVAL]       buf is the NULL pointer.
  44.      [CBEDUP]       A field in the record pointed to by buf contains
  45.                     an illegal duplicate key.
  46.      [CBELOCK]      cbp is not write locked.
  47.      [CBENOPEN]     cbp is not open.
  48.      [CBENREC]      The record cursor of cbp is null.
  49.  
  50. SEE ALSO
  51.      cbdelcur, cbgetr, cbinsert, cbrcursor.
  52.  
  53. DIAGNOSTICS
  54.      Upon successful completion, a value of 0 is returned.  Otherwise,
  55.      a value of -1 is returned, and errno set to indicate the error.
  56.  
  57. ------------------------------------------------------------------------------*/
  58. #ifdef AC_PROTO
  59. int cbputr(cbase_t *cbp, const void *buf)
  60. #else
  61. int cbputr(cbp, buf)
  62. cbase_t *cbp;
  63. const void *buf;
  64. #endif
  65. {
  66.     /* validate arguments */
  67.     if (!cb_valid(cbp)) {
  68.         errno = EINVAL;
  69.         return -1;
  70.     }
  71.     if (buf == NULL) {
  72.         errno = EINVAL;
  73.         return -1;
  74.     }
  75.  
  76.     /* check if not open */
  77.     if (!(cbp->flags & CBOPEN)) {
  78.         errno = CBENOPEN;
  79.         return -1;
  80.     }
  81.  
  82.     /* check if not write locked */
  83.     if (!(cbp->flags & CBWRLCK)) {
  84.         errno = CBELOCK;
  85.         return -1;
  86.     }
  87.  
  88.     /* check if record cursor is null */
  89.     if (lscursor(cbp->lsp) == NULL) {
  90.         errno = CBENREC;
  91.         return -1;
  92.     }
  93.  
  94.     /* delete current record */
  95.     if (cbdelcur(cbp) == -1) {
  96.         CBEPRINT;
  97.         return -1;
  98.     }
  99.  
  100.     /* back up cursor */
  101.     if (cbrecprev(cbp) == -1) {
  102.         CBEPRINT;
  103.         return -1;
  104.     }
  105.  
  106.     /* insert new record */
  107.     if (cbinsert(cbp, buf) == -1) {
  108.         CBEPRINT;
  109.         return -1;
  110.     }
  111.  
  112.     return 0;
  113. }
  114.